/**
   @file sys_usw_xdata_api.h

   @date 2022-06-16

   @version v1.0

   The file contains all scl APIs of sys layer

 */
#if defined(ARCTIC)
#ifndef _SYS_USW_XDATA_API_H
#define _SYS_USW_XDATA_API_H

#ifdef __cplusplus
extern "C" {
#endif
/****************************************************************************
*
* Header Files
*
****************************************************************************/
#include "sal.h"
#include "ctc_xdata.h"
#include "ctc_field.h"


/****************************************************************************
 *
 * Defines and Macros
 *
 *****************************************************************************/

/*replace the empty position*/
#define SYS_XDATA_FK_MODE_REPLACE1      0
/*expand the key type*/
#define SYS_XDATA_FK_MODE_APPEND        1
/*replace the whole key*/
#define SYS_XDATA_FK_MODE_REPLACE2      2

#define SYS_XDATA_FK_FIELD_NUM 32
#define SYS_XDATA_PORT_CID_POS 32

#define SYS_IPFIX_XBUS_RSV_DISCARD              17
#define SYS_IPFIX_XBUS_RSV_LANTENCY_CONGEST     28
#define SYS_IPFIX_XBUS_RSV_MICRO_BURST          28

enum sys_xdata_fk_f_type_e {
    SYS_FK_F_NONE,
    SYS_FK_F_PR_EXT_TYPE,
    SYS_FK_F_PR_EXT_DATA0,
    SYS_FK_F_PR_EXT_DATA1,
    SYS_FK_F_PR_EXT_DATA2,
    SYS_FK_F_PR_EXT_DATA3,
    SYS_FK_F_PR_EXT_DATA4,
    SYS_FK_F_PR_EXT_DATA5,
    SYS_FK_F_PR_L4_TYPE,
    SYS_FK_F_PR_L4_USER_TYPE,

    SYS_FK_F_PR_VNI0,
    SYS_FK_F_PR_VNI1,
    SYS_FK_F_STATIC_SRC_CID,
    SYS_FK_F_STATIC_DST_CID,
    SYS_FK_F_VLAN_RANGE_MAX_LO,
    SYS_FK_F_VLAN_RANGE_MAX_HI,
    SYS_FK_F_VLAN_RANGE_VALID,
    SYS_FK_F_VLAN_RANGE_TYPE,
    SYS_FK_F_VLAN_RANGE1_MAX_LO,
    SYS_FK_F_VLAN_RANGE1_MAX_HI,
    SYS_FK_F_VLAN_RANGE1_VALID,
    SYS_FK_F_VLAN_RANGE1_TYPE,
    SYS_FK_F_UDF_VALID,
    SYS_FK_F_UDF_HI_VALID,
    SYS_FK_F_UDF_HIT_INDEX,
    SYS_FK_F_UDF_HI_HIT_INDEX,
    SYS_FK_F_UDF_DATA0,
    SYS_FK_F_UDF_HI_DATA0,
    SYS_FK_F_UDF_DATA1,
    SYS_FK_F_UDF_HI_DATA1,
    SYS_FK_F_UDF_DATA2,
    SYS_FK_F_UDF_HI_DATA2,
    SYS_FK_F_UDF_DATA3,
    SYS_FK_F_UDF_HI_DATA3,
    SYS_FK_F_UDF_DATA4,
    SYS_FK_F_UDF_HI_DATA4,
    SYS_FK_F_UDF_DATA5,
    SYS_FK_F_UDF_HI_DATA5,
    SYS_FK_F_UDF_DATA6,
    SYS_FK_F_UDF_HI_DATA6,
    SYS_FK_F_UDF_HI_DATA7,
    SYS_FK_F_UDF_DATA7,
    SYS_FK_F_UDF_DATA4_HI,
    SYS_FK_F_UDF_DATA4_LO,
    SYS_FK_F_PKT_FWD_TYPE,
    SYS_FK_F_DST_CID,
    SYS_FK_F_PORT_CID,
    SYS_FK_F_VLAN_CID,
    SYS_FK_F_L3IF_CID,
    SYS_FK_F_VSI_CID,
    SYS_FK_F_TUNNEL_IF_CID,
    SYS_FK_F_DYNAMIC_SRC_CID,
    SYS_FK_F_DYNAMIC_DST_CID,
    SYS_FK_F_I2E_CID,
    SYS_FK_F_ACL_STATIC_SRC_CID,
    SYS_FK_F_ACL_STATIC_DST_CID,
    SYS_FK_F_LP_GRP,

    /*share xph field*/
    SYS_FK_F_PI_PKT_FWD_TYPE,
    SYS_FK_F_ECMP_HASH_HIGH,
    SYS_FK_F_SYSMETRIC_HASH_HIGH,
    SYS_FK_F_NAT_L4_SRC_PORT,
    SYS_FK_F_NAT_L4_DST_PORT,
    SYS_FK_F_EDIT_AUX_PTR,


    SYS_FK_F_FIELD_DONE,

    //new
    SYS_FK_F_PR_IP_HDR_ERROR,
    SYS_FK_F_PR_IP_TTL,
    SYS_FK_F_PRIORITY,
    SYS_FK_F_PR_L2_TYPE,
    SYS_FK_F_PR_L3_TYPE,
    SYS_FK_F_PR_VLAN_NUM,
    SYS_FK_F_PR_FRAG_INFO,
    SYS_FK_F_STP_STATE,
    SYS_FK_F_IS_DECAP,
    SYS_FK_F_ROUTED_PKT,
    SYS_FK_F_TUNNEL_TYPE,
    SYS_FK_F_DISCARD,
    SYS_FK_F_DISCARD_TYPE,
    SYS_FK_F_CVLAN_ID_VALID,
    SYS_FK_F_SVLAN_ID_VALID,
    SYS_FK_F_CVLAN_ID_LO,
    SYS_FK_F_SVLAN_ID_LO,
    SYS_FK_F_CVLAN_ID_HI,
    SYS_FK_F_SVLAN_ID_HI,
    SYS_FK_F_L3_IF_ID,
    SYS_FK_F_LOGIC_SRC_PORT,
    SYS_FK_F_FID,
    SYS_FK_F_VRF_ID,
    SYS_FK_F_UDF_HIT_INDEX_LO,
    SYS_FK_F_LANTENCY_CONGEST_VALID,
    SYS_FK_F_MICRO_BURST_VALID,
    SYS_FK_F_SRC_GPORT,
    SYS_FK_F_MAX,

    SYS_FK_F_XDATA_NIBBLE0 = SYS_FK_F_MAX,
    SYS_FK_F_XDATA_NIBBLE1,
    SYS_FK_F_XDATA_NIBBLE2,
    SYS_FK_F_XDATA_NIBBLE3,
    SYS_FK_F_XDATA_BYTE0,
    SYS_FK_F_XDATA_BYTE1,
    SYS_FK_F_XDATA_BYTE2,
    SYS_FK_F_XDATA_BYTE3,
    SYS_FK_F_XDATA_BYTE4,
    SYS_FK_F_XDATA_BYTE5,
    SYS_FK_F_XDATA_WORD0,
    SYS_FK_F_XDATA_WORD1,
    SYS_FK_F_XDATA_WORD2,
    SYS_FK_F_XDATA_WORD3,
    SYS_FK_F_XDATA
};
typedef enum  sys_xdata_fk_f_type_e sys_xdata_fk_f_type_t;

enum sys_xdata_local_type_e
{
    SYS_XDATA_LOCAL_TYPE_TUNNEL = CTC_XDATA_LOCAL_TYPE_MAX,
    SYS_XDATA_LOCAL_TYPE_UDF,
    SYS_XDATA_LOCAL_TYPE_MAC,
    SYS_XDATA_LOCAL_TYPE_IP,
    SYS_XDATA_LOCAL_TYPE_XHASH,
    SYS_XDATA_LOCAL_TYPE_MAX,
};
typedef enum sys_xdata_local_type_e sys_xdata_local_type_t;

enum sys_xdata_prof_type_e
{
    SYS_XDATA_PROF_TYPE_DSMET = CTC_XDATA_PROF_TYPE_MAX,
    SYS_XDATA_PROF_TYPE_MAX
};
typedef enum sys_xdata_prof_type_e sys_xdata_prof_type_t;


struct sys_xdata_fk_field_s
{
   /*field information*/
    uint8 field;  /* refer to sys_xdata_fk_f_type_t */
    char *ptr_field_name;
    uint32 flags;
    uint16 mask;        /*xdata mask*/
    uint8 src_pos;      /*xdata position in 4 bits*/
    uint8 width;        /*xdata width*/
    uint8 start_bit;
    uint8 share_field; /*sys_xpi_field_t*/
};
typedef struct sys_xdata_fk_field_s sys_xdata_fk_field_t;


struct sys_xdata_fk_s
{
    uint32 tbl_id;  /*hash/tcam or Normal tabel*/
    uint8 type;   /* sys_xdata_local_type_t */
    uint8 mode;     /*refer to SYS_XDATA_FK_MODE_XXX*/

    uint8 direct_index_en;
    uint16 flex_bits;  /* out */
    uint8 hash_type;   /* 0xFF:tcam, !0xFF:Hash */
    uint32 direct_max_index;
    uint32 direct_index_mask;

    /*field information*/
    sys_xdata_fk_field_t info;
};
typedef struct sys_xdata_fk_s sys_xdata_fk_t;

struct sys_xdata_fk_io_s
{
    uint32 type;/* refer to sys_xdata_local_type_t */
    uint32 tbl_id;
    uint32 hash_type;
    uint8 fk_field;
    ctc_xdata_t* xdata;
};
typedef struct sys_xdata_fk_io_s sys_xdata_fk_io_t;

extern int32
sys_usw_xdata_init(uint8 lchip);

extern int32
sys_usw_xdata_deinit(uint8 lchip);

extern int32
sys_usw_xdata_set_profile(uint8 lchip, ctc_xdata_prof_t * p_prof);

extern int32
sys_usw_xdata_get_profile(uint8 lchip, ctc_xdata_prof_t * p_prof);

extern int32
sys_usw_xdata_set_path(uint8 lchip, ctc_xdata_path_t * p_path);

extern int32
sys_usw_xdata_get_path(uint8 lchip, ctc_xdata_path_t * p_path);

extern int32
sys_usw_xdata_set_local(uint8 lchip, ctc_xdata_local_t * p_local);

extern int32
sys_usw_xdata_get_local(uint8 lchip, ctc_xdata_local_t * p_local);

extern int32
sys_usw_xdata_prof_get_info(uint8 lchip, ctc_xdata_t * p_prof, uint8 with_check);

extern int32
sys_usw_xdata_local_get_kset(uint8 lchip, ctc_xdata_local_type_t type, void * kset);

extern int32
sys_usw_xdata_func_en(uint8 lchip, sys_xdata_func_t type, uint8 enable, void* data);


#ifdef __cplusplus
}
#endif
#endif
#endif


